package util;

import entity.User;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserUtil {
    // 私有化构造方法，防止外部创建对象
    private UserUtil() {
    }

    /**
     * 工具方法，用于从ResultSet构建User对象
     *
     * @param rs
     * @return
     * @throws SQLException
     */
    public static User rsToUser(ResultSet rs) throws SQLException {
        User user = new User();
        user.setId(rs.getInt("id"));
        user.setUsername(rs.getString("username"));
        user.setPassword(rs.getString("password"));
        user.setEmail(rs.getString("email"));
        user.setPhone(rs.getString("phone"));
        user.setCreated(rs.getTimestamp("created"));
        user.setUpdated(rs.getTimestamp("updated"));
        return user;
    }
}
